<?php
/*
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
//公众号操作员设置。管理公众号操作员，对操作员进行增删查改。
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'list';
$return=array();
if(!$_SESSION['isfounder']){
	exi('error','error','goback');
}

if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid']);
	$return['list']=pdo_getall('core_user_groups',$params,array('id','uniacid','title','welcome'));
	$htmls=array(
		'type'=>'list',
		'tabs'=>array(
			array('op'=>'list','title'=>'角色列表'),
		),
		'list'=>array('data'=>'list','list'=>array(
			array('name'=>'id','title'=>'角色ID','type'=>'string'),
			array('name'=>'title','title'=>'角色名称','type'=>'string'),
			array('name'=>'welcome','title'=>'登录后跳转地址','type'=>'string'),
		)),
		'search_one'=>array('name'=>'title'),
	);
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='edit'){
	$uid=intval($_RQ['id']);
	
		
	if($uid){
		$item=pdo_get('core_user_groups',array('id'=>$uid,'uniacid'=>$_SESSION['uniacid']));
	}else{
		$item=array();
	}
	$return['item']=$item;
	$htmls=array(
		'type'=>'edit',
		'post'=>'post',
		'desc'=>'角色',
		'tabs'=>array(
			array('op'=>'list','title'=>'角色列表'),
			array('op'=>'edit','title'=>'添加角色'),
		),
		'edit'=>array(
			array('type'=>'string','title'=>'角色名称','name'=>'title', 'help'=>'' ),
			array('type'=>'string','title'=>'登录后跳转地址','name'=>'welcome', 'help'=>'' ),
			array('type'=>'checkbox','title'=>'主菜单设置','name'=>'perm1','options'=>'perm1','help'=>'设置主菜单权限'),
			array('type'=>'checkbox','title'=>'子菜单设置','name'=>'perm2','options'=>'perm2','help'=>'设置子菜单权限' ,'help'=>'要使用子菜单权限必须添加子菜单的主菜单权限'),
		)
	);
	
	$menu=cfc('jy_paimai')->menu();
	foreach($menu as $v){
		$k=$v['url'];
		$return['perm1'][$k]=$v['title'];
		foreach($v['child'] as $c){
			foreach($c['child'] as $x){
			$e=$x['url'];
			$return['perm2'][$e]=$x['title'];
		}
		}
	}
	$return['htmls']=$htmls;
	exi($return);
}
if($_RQ['op']=='post'){
	$postdata=get_postdata();
	
	$id=intval($postdata['id']);
	
	$data=array(
		'title'=>$postdata['title'],
		'welcome'=>$postdata['welcome'],
		'perm1'=>$postdata['perm1'],
		'perm2'=>$postdata['perm2'],
	);
	if($id){
		pdo_update('core_user_groups',$data,array('uniacid'=>$_SESSION['uniacid'],'id'=>$id));
		
		$message='修改角色成功！';
	}else{
		$data['uniacid']=$_SESSION['uniacid'];
		pdo_insert('core_user_groups',$data);
		$message='添加操作员成功！';
	}
	
	exi($message,'','list');
}
if($_RQ['op']=='del'){
	$id=intval($_RQ['id']);
	if($id){
		pdo_delete('core_user_groups',array('id'=>$id));
		
	}
	$del=trim($_RQ['del'],';');
	if($del){
		$del=explode(';',$del);
		foreach($del as $id){
			$id=intval($id);
			if($id){
				pdo_delete('core_user_groups',array('id'=>$id));
				
			}
		}
	}
	exi('删除成功！');
}
?>